# 贪心算法，买卖股票



class Solution:
    def maxProfit(self, prices):

        cost, profit = float("+inf"), 0

        for price in prices:
            cost = min(cost, price)
            profit = max(profit, price - cost) # 这个函数很巧妙

        
        return profit
    

if __name__ == "__main__":

    p = [7,1,5,3,6,4]
    sol = Solution()
    res = sol.maxProfit(p)
    print(res)

